|
|
|
|
|
|
|
If an error is trapped by an error-handling routine, and control is passed to the error routine, the only way to deactivate and return from the routine is to execute one of the three forms of the Resume statement: |
|
|
|
|
|
|
|
|
The first type specifies the line number or the label where you want control of the application execution to be returned. The second type causes execution to continue from the statement immediately following the one that caused the error. Finally, the third version will re-execute the statement that had the error. If the error routine has resolved the reason the error occurred, you can use the third version to retry the operation. The best example of this would be when the user tries to save a file to a disk and there is no disk in the drive. An error will occur and the error routine will be executed. In the error routine, the user is told to insert a disk and click the OK button of the MessageBox. When this is done, the application will retry the save operation. Of course, you should give the user the capability to cancel the operation altogether. |
|
|
|
|
|
|
|
|
The Built-in Error Objects |
|
|
|
|
|
|
|
|
Among the many objects that are included in Visual Basic, there are two that you can use to track and report errors that occur during the execution of your application. The Err and Error objects provide useful information about the error that has just occurred. |
|
|
|
|
|
|
|
|
The Err object exists and can be accessed anywhere in a Visual Basic application. Each time an error occurs in the application the Err object's properties will be populated with the information about the current error. The object contains several properties and two methods, listed in Table 16.2, that you can use in the process. |
|
|
|
|
| TABLE 16.2. THE METHODS AND PROPERTIES OF THEERROBJECT. | | Type | Description | | | Number | The Visual Basic error number | | Source | Name of the current Visual Basic file here the error occurred | | Description | The description of the error number found in the Number property | | HelpFile | The full path and filename of the Help file that supports the reported error | | HelpContext | The Help topic ID in the help file indicated in the preceding property |
|
|
|
|
|
|
(table continued on next page) |
|
|
|
|
|